<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta title="template local_template.html">
<title>Code Quality</title></head>
<body>
<div id="main_title">Code Quality</div>
<div id="content">

<p>Code Quality Analyzers are tools which can analyze the quality of code, make reports
about when something bad is found, and optionally provide a score 
indicative of the quality of the code.</p>

<p>Those tools are not a part of Crunchy, you must install them on your
computer. Currently, there are three supported analyzers:</p>
<ul>
<li><a href="http://www.logilab.org/857" title="external_link">Pylint</a></li>
<li><a href="http://pychecker.sourceforge.net/" title="external_link">PyChecker</a></li>
<li><a href="http://divmod.org/trac/wiki/DivmodPyflakes" title="external_link">PyFlakes</a>; 
you need the version from the repository for it to work with Crunchy.  Note that
PyFlakes is probably the least useful of the three that are listed here.</li>
</ul>

<h2>Configuration</h2>

<p>You can choose your analyzer (or disable analysis) using the following:</p>
<div title="preferences analyzer">irrelevant text</div>
<p>Note that only those analyzers that Crunchy can find on your system are
listed as available.</p>
<div class="notes">
<h4>Show vlam</h4>
<p> In what follows, we have used the "show_vlam" option to display automatically
what vlam is used for a particular example.  Of course, you do not need to include this option
to make a similar example work.
</p>
</div>


<h2>Performing a code analysis</h2>

<p>Please notice that the report and the score displayed heavy depend on
what analyzer you use. Pylint is far more severe than PyChecker.</p>

<p>The analyzer plugin add several <acronym title="Very Little Additional
Markup">VLAM</acronym> options:</p>

<ul>
<li><code>analyzer</code>: a new widget to make analysis</li>
<li><code>analyzer_score</code>: for editors, doctest and unittest, display
the score after the normal execution</li>
<li><code>analyzer_report</code>: for editors, doctest and unittest, add a
button to analyze the code</li>
</ul>

<h3>The analyzer widget</h3>

<p>The analyzer widget is an editor with a button to make a report and a score
about the code.</p>

<p>Here is some code that will raise warnings with Pylint (PyChecker fails to
analyze it):</p>

<pre title="analyzer show_vlam">
def Function_without_DocString(msg):
    print msg

foo=missingvar
Function_without_DocString(missingvar)
</pre>

<p>Here is another less than ideal code sample, to try with PyChecker:</p>
<pre title="analyzer show_vlam">
# Unused import
import this
# Statement with no effect
True
# Nice, well known and useful piece of code
print "Hello world"
</pre>

<h3>With the editor</h3>

<p>Here is an editor with the <code>analyzer_score</code> option (<em>this
doesn't add another button, but let the existing one display the score reported
by the analyzer</em>):</p>
<pre title="editor analyzer_score show_vlam">
def Function_without_DocString(msg = []):
    this_variable_is_not_used = 42
    print ' '.join(msg)

Function_without_DocString(['Hello', 'world'])
</pre>

<h3>With doctest</h3>

<p>Here is a doctest editor with the <code>analyzer_report</code> option:</p>
<pre title="doctest analyzer_report show_vlam">
This force your function to have a bad name:
    >>> Function_with_A_BadName(['A', 'message'])
    A message
</pre>

<p>You can try this code:</p>
<pre title="py_code">
def Function_with_A_BadName(msg = []):
    this_variable_is_not_used = 42
    print ' '.join(msg)
</pre>

<h3>With unittest</h3>

<p>And here a unittest editor with both <code>analyze_report</code> and
<code>analyzer_score</code>:</p>

<pre title="unittest analyzer_report analyzer_score show_vlam">
class BadCodeTest(unittest.TestCase):
    """Test class for the bad_named_class class"""
    def test_bad_named_class(self):
        """Tests for the initialization of bad_named_class"""
        bad_object = bad_named_class()
        self.assertEquals(bad_object.BadAttribName, 42)
</pre>

<p>You can try this code:</p>
<pre title="py_code">
class bad_named_class(object):
    BadAttribName = 42
</pre>
</div>
</body>
</html>
